package c.e.b.h.e.k;

import android.content.Context;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.text.TextUtils;
import android.util.Log;
import c.e.a.b.g.a0;
import c.e.a.b.g.b0;
import c.e.b.h.e.m.v;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.Flushable;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;

/* compiled from: CrashlyticsController */
public class t {
    public static final Comparator<File> A = new e();
    public static final Pattern B = Pattern.compile("([\\d|A-Z|a-z]{12}\\-[\\d|A-Z|a-z]{4}\\-[\\d|A-Z|a-z]{4}\\-[\\d|A-Z|a-z]{12}).+");
    public static final Map<String, String> C = Collections.singletonMap("X-CRASHLYTICS-SEND-FLAGS", "1");
    public static final String[] D = new String[]{"SessionUser", "SessionApp", "SessionOS", "SessionDevice"};
    public static final FilenameFilter x = new a("BeginSession");
    public static final FilenameFilter y = new c();
    public static final Comparator<File> z = new d();
    public final Context a;
    public final l0 b;
    public final h0 c;
    public final y0 d;
    public final h e;
    public final c.e.b.h.e.n.c f;
    public final q0 g;
    public final c.e.b.h.e.o.h h;
    public final b i;
    public final c.e.b.h.e.q.b.b j;
    public final k k;
    public final c.e.b.h.e.l.b l;
    public final c.e.b.h.e.q.a m;
    public final c.e.b.h.e.q.b.a n;
    public final c.e.b.h.e.a o;
    public final c.e.b.h.e.t.d p;
    public final String q;
    public final c.e.b.h.e.i.a r;
    public final w0 s;
    public k0 t;
    public c.e.a.b.g.h<Boolean> u = new c.e.a.b.g.h();
    public c.e.a.b.g.h<Boolean> v = new c.e.a.b.g.h();
    public c.e.a.b.g.h<Void> w = new c.e.a.b.g.h();

    /* compiled from: CrashlyticsController */
    public class b implements Callable<Void> {
        public final /* synthetic */ long a;

        public b(long j) {
            this.a = j;
        }

        public Object call() throws Exception {
            Bundle bundle = new Bundle();
            bundle.putInt("fatal", 1);
            bundle.putLong("timestamp", this.a);
            t.this.r.a("_ae", bundle);
            return null;
        }
    }

    /* compiled from: CrashlyticsController */
    public class c implements FilenameFilter {
        public boolean accept(File file, String str) {
            return str.length() == 39 && str.endsWith(".cls");
        }
    }

    /* compiled from: CrashlyticsController */
    public class d implements Comparator<File> {
        public int compare(Object obj, Object obj2) {
            return ((File) obj2).getName().compareTo(((File) obj).getName());
        }
    }

    /* compiled from: CrashlyticsController */
    public class e implements Comparator<File> {
        public int compare(Object obj, Object obj2) {
            return ((File) obj).getName().compareTo(((File) obj2).getName());
        }
    }

    /* compiled from: CrashlyticsController */
    public static class g implements FilenameFilter {
        public g(a aVar) {
        }

        public boolean accept(File file, String str) {
            return !((c) t.y).accept(file, str) && t.B.matcher(str).matches();
        }
    }

    /* compiled from: CrashlyticsController */
    public interface h {
        void a(c.e.b.h.e.p.c cVar) throws Exception;
    }

    /* compiled from: CrashlyticsController */
    public static class i implements FilenameFilter {
        public final String a;

        public i(String str) {
            this.a = str;
        }

        public boolean accept(File file, String str) {
            return str.contains(this.a) && !str.endsWith(".cls_temp");
        }
    }

    /* compiled from: CrashlyticsController */
    public static class j implements FilenameFilter {
        public boolean accept(File file, String str) {
            return ((c.e.b.h.e.p.b.a) c.e.b.h.e.p.b.d).accept(file, str) || str.contains("SessionMissingBinaryImages");
        }
    }

    /* compiled from: CrashlyticsController */
    public static final class n implements Runnable {
        public final Context a;
        public final c.e.b.h.e.q.c.c b;
        public final c.e.b.h.e.q.b c;
        public final boolean d;

        public n(Context context, c.e.b.h.e.q.c.c cVar, c.e.b.h.e.q.b bVar, boolean z) {
            this.a = context;
            this.b = cVar;
            this.c = bVar;
            this.d = z;
        }

        public void run() {
            if (g.b(this.a)) {
                c.e.b.h.e.b.a.b("Attempting to send crash report at time of crash...");
                this.c.a(this.b, this.d);
            }
        }
    }

    /* compiled from: CrashlyticsController */
    public static class o implements FilenameFilter {
        public final String a;

        public o(String str) {
            this.a = str;
        }

        public boolean accept(File file, String str) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(this.a);
            stringBuilder.append(".cls");
            boolean z = false;
            if (str.equals(stringBuilder.toString())) {
                return false;
            }
            if (str.contains(this.a) && !str.endsWith(".cls_temp")) {
                z = true;
            }
            return z;
        }
    }

    /* compiled from: CrashlyticsController */
    public class a extends i {
        public a(String str) {
            super(str);
        }

        public boolean accept(File file, String str) {
            return super.accept(file, str) && str.endsWith(".cls");
        }
    }

    /* compiled from: CrashlyticsController */
    public class f implements c.e.a.b.g.f<Boolean, Void> {
        public final /* synthetic */ c.e.a.b.g.g a;
        public final /* synthetic */ float b;

        public f(c.e.a.b.g.g gVar, float f) {
            this.a = gVar;
            this.b = f;
        }

        public c.e.a.b.g.g a(Object obj) throws Exception {
            return t.this.e.c(new b0(this, (Boolean) obj));
        }
    }

    /* compiled from: CrashlyticsController */
    public static final class k implements c.e.b.h.e.l.b.b {
        public final c.e.b.h.e.o.h a;

        public k(c.e.b.h.e.o.h hVar) {
            this.a = hVar;
        }

        public File a() {
            File file = new File(this.a.a(), "log-files");
            if (!file.exists()) {
                file.mkdirs();
            }
            return file;
        }
    }

    /* compiled from: CrashlyticsController */
    public final class l implements c.e.b.h.e.q.b.c {
        public l(a aVar) {
        }
    }

    /* compiled from: CrashlyticsController */
    public final class m implements c.e.b.h.e.q.b.a {
        public m(a aVar) {
        }
    }

    public t(Context context, h hVar, c.e.b.h.e.n.c cVar, q0 q0Var, l0 l0Var, c.e.b.h.e.o.h hVar2, h0 h0Var, b bVar, c.e.b.h.e.q.a aVar, c.e.b.h.e.q.b.b bVar2, c.e.b.h.e.a aVar2, c.e.b.h.e.u.a aVar3, c.e.b.h.e.i.a aVar4, c.e.b.h.e.s.e eVar) {
        Context context2 = context;
        q0 q0Var2 = q0Var;
        c.e.b.h.e.o.h hVar3 = hVar2;
        b bVar3 = bVar;
        c.e.b.h.e.u.a aVar5 = aVar3;
        AtomicInteger atomicInteger = new AtomicInteger(0);
        AtomicBoolean atomicBoolean = new AtomicBoolean(false);
        this.a = context2;
        this.e = hVar;
        this.f = cVar;
        this.g = q0Var2;
        this.b = l0Var;
        this.h = hVar3;
        this.c = h0Var;
        this.i = bVar3;
        this.j = new c0(this);
        this.o = aVar2;
        if (!aVar5.b) {
            String string;
            Context context3 = aVar5.a;
            int m = g.m(context3, "com.google.firebase.crashlytics.unity_version", "string");
            if (m != 0) {
                string = context3.getResources().getString(m);
                c.b.a.a.a.u("Unity Editor version is: ", string, c.e.b.h.e.b.a);
            } else {
                string = null;
            }
            aVar5.c = string;
            aVar5.b = true;
        }
        String str = aVar5.c;
        if (str == null) {
            str = null;
        }
        this.q = str;
        this.r = aVar4;
        y0 y0Var = new y0();
        this.d = y0Var;
        k kVar = new k(hVar3);
        this.k = kVar;
        c.e.b.h.e.l.b bVar4 = new c.e.b.h.e.l.b(context, kVar);
        this.l = bVar4;
        this.m = new c.e.b.h.e.q.a(new l(null));
        this.n = new m(null);
        c.e.b.h.e.t.a aVar6 = new c.e.b.h.e.t.a(1024, new c.e.b.h.e.t.c(10));
        this.p = aVar6;
        File file = new File(new File(hVar3.a.getFilesDir(), ".com.google.firebase.crashlytics").getPath());
        i0 i0Var = new i0(context, q0Var2, bVar3, aVar6);
        c.e.b.h.e.o.g gVar = new c.e.b.h.e.o.g(file, eVar);
        c.e.b.h.e.m.x.h hVar4 = c.e.b.h.e.r.c.b;
        c.e.a.a.f.k.b(context);
        c.e.a.a.f.k a = c.e.a.a.f.k.a();
        c.e.a.a.e.a aVar7 = new c.e.a.a.e.a(c.e.b.h.e.r.c.c, c.e.b.h.e.r.c.d);
        Objects.requireNonNull(a);
        Set unmodifiableSet = Collections.unmodifiableSet(c.e.a.a.e.a.f);
        c.e.a.a.f.h.a a2 = c.e.a.a.f.h.a();
        a2.b("cct");
        c.e.a.a.f.b.b bVar5 = (c.e.a.a.f.b.b) a2;
        bVar5.b = aVar7.b();
        c.e.a.a.f.h a3 = bVar5.a();
        c.e.a.a.a aVar8 = new c.e.a.a.a("json");
        c.e.a.a.c cVar2 = c.e.b.h.e.r.c.e;
        if (unmodifiableSet.contains(aVar8)) {
            this.s = new w0(i0Var, gVar, new c.e.b.h.e.r.c(new c.e.a.a.f.i(a3, "FIREBASE_CRASHLYTICS_REPORT", aVar8, cVar2, a), cVar2), bVar4, y0Var);
        } else {
            throw new IllegalArgumentException(String.format("%s is not supported byt this factory. Supported encodings are: %s.", new Object[]{aVar8, unmodifiableSet}));
        }
    }

    public static void A(c.e.b.h.e.p.c cVar, File file) throws IOException {
        Throwable th;
        String str = "Failed to close file input stream.";
        if (file.exists()) {
            Closeable closeable = null;
            try {
                FileInputStream fileInputStream = new FileInputStream(file);
                try {
                    e(fileInputStream, cVar, (int) file.length());
                    g.c(fileInputStream, str);
                    return;
                } catch (Throwable th2) {
                    th = th2;
                    closeable = fileInputStream;
                    g.c(closeable, str);
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
                g.c(closeable, str);
                throw th;
            }
        }
        c.e.b.h.e.b bVar = c.e.b.h.e.b.a;
        StringBuilder g = c.b.a.a.a.g("Tried to include a file that doesn't exist: ");
        g.append(file.getName());
        bVar.d(g.toString());
    }

    public static void a(t tVar) throws Exception {
        t tVar2 = tVar;
        Objects.requireNonNull(tVar);
        long j = j();
        f fVar = new f(tVar2.g);
        String str = f.b;
        c.e.b.h.e.b bVar = c.e.b.h.e.b.a;
        c.b.a.a.a.u("Opening a new session with ID ", str, bVar);
        tVar2.o.g(str);
        Locale locale = Locale.US;
        Object[] objArr = new Object[1];
        String str2 = "17.2.2";
        objArr[0] = str2;
        String format = String.format(locale, "Crashlytics Android SDK/%s", objArr);
        tVar2.z(str, "BeginSession", new q(tVar, str, format, j));
        tVar2.o.e(str, format, j);
        q0 q0Var = tVar2.g;
        String str3 = q0Var.c;
        b bVar2 = tVar2.i;
        String str4 = bVar2.e;
        format = bVar2.f;
        String b = q0Var.b();
        String str5 = str2;
        r rVar = r1;
        int i = n0.a(tVar2.i.c).a;
        String str6 = format;
        r rVar2 = new r(tVar, str3, str4, format, b, i);
        tVar2.z(str, "SessionApp", rVar);
        String str7 = str5;
        tVar2.o.d(str, str3, str4, str6, b, i, tVar2.q);
        str2 = VERSION.RELEASE;
        str3 = VERSION.CODENAME;
        boolean s = g.s(tVar2.a);
        tVar2.z(str, "SessionOS", new s(tVar2, str2, str3, s));
        tVar2.o.f(str, str2, str3, s);
        Context context = tVar2.a;
        StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
        Enum enumR = c.e.b.h.e.k.g.b.UNKNOWN;
        str4 = Build.CPU_ABI;
        if (TextUtils.isEmpty(str4)) {
            bVar.b("Architecture#getValue()::Build.CPU_ABI returned null or empty");
        } else {
            Enum enumR2 = (c.e.b.h.e.k.g.b) c.e.b.h.e.k.g.b.k.get(str4.toLowerCase(locale));
            if (enumR2 != null) {
                enumR = enumR2;
            }
        }
        i = enumR.ordinal();
        String str8 = Build.MODEL;
        int availableProcessors = Runtime.getRuntime().availableProcessors();
        long o = g.o();
        str5 = str7;
        long blockCount = ((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize());
        boolean q = g.q(context);
        int j2 = g.j(context);
        format = Build.MANUFACTURER;
        long j3 = j;
        String str9 = str5;
        u uVar = r1;
        String str10 = Build.PRODUCT;
        String str11 = str8;
        String str12 = format;
        String str13 = str3;
        String str14 = str4;
        String str15 = str2;
        Locale locale2 = locale;
        c.e.b.h.e.b bVar3 = bVar;
        String str16 = str9;
        str9 = str;
        u uVar2 = new u(tVar, i, str8, availableProcessors, o, blockCount, q, j2, str12, str10);
        tVar2.z(str9, "SessionDevice", uVar);
        tVar2.o.c(str9, i, str11, availableProcessors, o, blockCount, q, j2, str12, str10);
        tVar2.l.a(str9);
        w0 w0Var = tVar2.s;
        String u = u(str9);
        i0 i0Var = w0Var.a;
        Objects.requireNonNull(i0Var);
        Charset charset = v.a;
        c.e.b.h.e.m.b.b bVar4 = new c.e.b.h.e.m.b.b();
        bVar4.a = str16;
        String str17 = i0Var.c.a;
        Objects.requireNonNull(str17, "Null gmpAppId");
        bVar4.b = str17;
        str17 = i0Var.b.b();
        Objects.requireNonNull(str17, "Null installationUuid");
        bVar4.d = str17;
        str17 = i0Var.c.e;
        String str18 = "Null buildVersion";
        Objects.requireNonNull(str17, str18);
        bVar4.e = str17;
        str17 = i0Var.c.f;
        Objects.requireNonNull(str17, "Null displayVersion");
        bVar4.f = str17;
        bVar4.c = Integer.valueOf(4);
        c.e.b.h.e.m.f.b bVar5 = new c.e.b.h.e.m.f.b();
        bVar5.b(false);
        bVar5.c = Long.valueOf(j3);
        str8 = "Null identifier";
        Objects.requireNonNull(u, str8);
        bVar5.b = u;
        u = i0.e;
        Objects.requireNonNull(u, "Null generator");
        bVar5.a = u;
        str3 = i0Var.b.c;
        Objects.requireNonNull(str3, str8);
        str4 = i0Var.c.e;
        u = "Null version";
        Objects.requireNonNull(str4, u);
        bVar5.f = new c.e.b.h.e.m.g(str3, str4, i0Var.c.f, null, i0Var.b.b(), null);
        Integer valueOf = Integer.valueOf(3);
        str3 = str15;
        Objects.requireNonNull(str3, u);
        u = str13;
        Objects.requireNonNull(u, str18);
        Boolean valueOf2 = Boolean.valueOf(g.s(i0Var.a));
        str4 = valueOf == null ? " platform" : "";
        if (valueOf2 == null) {
            str4 = c.b.a.a.a.D(str4, " jailbroken");
        }
        if (str4.isEmpty()) {
            bVar5.h = new c.e.b.h.e.m.t(valueOf.intValue(), str3, u, valueOf2.booleanValue(), null);
            StatFs statFs2 = new StatFs(Environment.getDataDirectory().getPath());
            int i2 = 7;
            if (!TextUtils.isEmpty(str14)) {
                Integer num = (Integer) i0.f.get(str14.toLowerCase(locale2));
                if (num != null) {
                    i2 = num.intValue();
                }
            }
            int availableProcessors2 = Runtime.getRuntime().availableProcessors();
            long o2 = g.o();
            long blockCount2 = ((long) statFs2.getBlockCount()) * ((long) statFs2.getBlockSize());
            s = g.q(i0Var.a);
            int j4 = g.j(i0Var.a);
            c.e.b.h.e.m.i.b bVar6 = new c.e.b.h.e.m.i.b();
            bVar6.a = Integer.valueOf(i2);
            str = str11;
            Objects.requireNonNull(str, "Null model");
            bVar6.b = str;
            bVar6.c = Integer.valueOf(availableProcessors2);
            bVar6.d = Long.valueOf(o2);
            bVar6.e = Long.valueOf(blockCount2);
            bVar6.f = Boolean.valueOf(s);
            bVar6.g = Integer.valueOf(j4);
            str7 = str12;
            Objects.requireNonNull(str7, "Null manufacturer");
            bVar6.h = str7;
            str7 = str10;
            Objects.requireNonNull(str7, "Null modelClass");
            bVar6.i = str7;
            bVar5.i = bVar6.a();
            bVar5.k = Integer.valueOf(3);
            bVar4.g = bVar5.a();
            v a = bVar4.a();
            c.e.b.h.e.o.g gVar = w0Var.b;
            Objects.requireNonNull(gVar);
            c.e.b.h.e.m.v.d h = a.h();
            if (h == null) {
                bVar3.b("Could not get session for report");
                return;
            }
            c.e.b.h.e.b bVar7 = bVar3;
            str7 = h.g();
            try {
                File h2 = gVar.h(str7);
                c.e.b.h.e.o.g.i(h2);
                c.e.b.h.e.o.g.l(new File(h2, "report"), c.e.b.h.e.o.g.i.g(a));
                return;
            } catch (IOException e) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("Could not persist report for session ");
                stringBuilder.append(str7);
                bVar7.c(stringBuilder.toString(), e);
                return;
            }
        }
        throw new IllegalStateException(c.b.a.a.a.D("Missing required properties:", str4));
    }

    public static c.e.a.b.g.g b(t tVar) {
        Objects.requireNonNull(tVar);
        ArrayList arrayList = new ArrayList();
        for (File file : r(tVar.l(), l.a)) {
            try {
                arrayList.add(tVar.t(Long.parseLong(file.getName().substring(3))));
            } catch (NumberFormatException unused) {
                c.e.b.h.e.b bVar = c.e.b.h.e.b.a;
                StringBuilder g = c.b.a.a.a.g("Could not parse timestamp from file ");
                g.append(file.getName());
                bVar.b(g.toString());
            }
            file.delete();
        }
        return c.e.a.b.b.j.d.g(arrayList);
    }

    public static void c(String str, File file) throws Exception {
        Throwable th;
        StringBuilder g;
        if (str != null) {
            String str2 = "Failed to close ";
            String str3 = "Failed to flush to append to ";
            Flushable flushable = null;
            Closeable fileOutputStream;
            try {
                fileOutputStream = new FileOutputStream(file, true);
                try {
                    flushable = c.e.b.h.e.p.c.l(fileOutputStream);
                    c.e.b.h.e.p.a aVar = c.e.b.h.e.p.d.a;
                    c.e.b.h.e.p.a a = c.e.b.h.e.p.a.a(str);
                    flushable.t(7, 2);
                    int b = c.e.b.h.e.p.c.b(2, a);
                    flushable.r((c.e.b.h.e.p.c.d(b) + c.e.b.h.e.p.c.f(5)) + b);
                    flushable.t(5, 2);
                    flushable.r(b);
                    flushable.o(2, a);
                    StringBuilder g2 = c.b.a.a.a.g(str3);
                    g2.append(file.getPath());
                    g.g(flushable, g2.toString());
                    g2 = new StringBuilder();
                    g2.append(str2);
                    g2.append(file.getPath());
                    g.c(fileOutputStream, g2.toString());
                } catch (Throwable th2) {
                    th = th2;
                    g = c.b.a.a.a.g(str3);
                    g.append(file.getPath());
                    g.g(flushable, g.toString());
                    g = new StringBuilder();
                    g.append(str2);
                    g.append(file.getPath());
                    g.c(fileOutputStream, g.toString());
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
                fileOutputStream = null;
                g = c.b.a.a.a.g(str3);
                g.append(file.getPath());
                g.g(flushable, g.toString());
                g = new StringBuilder();
                g.append(str2);
                g.append(file.getPath());
                g.c(fileOutputStream, g.toString());
                throw th;
            }
        }
    }

    public static void e(InputStream inputStream, c.e.b.h.e.p.c cVar, int i) throws IOException {
        byte[] bArr = new byte[i];
        int i2 = 0;
        while (i2 < i) {
            int read = inputStream.read(bArr, i2, i - i2);
            if (read < 0) {
                break;
            }
            i2 += read;
        }
        Objects.requireNonNull(cVar);
        int i3 = cVar.b;
        i2 = cVar.c;
        i3 -= i2;
        if (i3 >= i) {
            System.arraycopy(bArr, 0, cVar.a, i2, i);
            cVar.c += i;
            return;
        }
        System.arraycopy(bArr, 0, cVar.a, i2, i3);
        i2 = i3 + 0;
        i -= i3;
        cVar.c = cVar.b;
        cVar.m();
        if (i <= cVar.b) {
            System.arraycopy(bArr, i2, cVar.a, 0, i);
            cVar.c = i;
            return;
        }
        cVar.d.write(bArr, i2, i);
    }

    public static long j() {
        return new Date().getTime() / 1000;
    }

    public static String o(File file) {
        return file.getName().substring(0, 35);
    }

    public static File[] r(File file, FilenameFilter filenameFilter) {
        File[] listFiles = file.listFiles(filenameFilter);
        return listFiles == null ? new File[0] : listFiles;
    }

    public static String u(String str) {
        return str.replaceAll("-", "");
    }

    public static void x(c.e.b.h.e.p.c cVar, File[] fileArr, String str) {
        c.e.b.h.e.b bVar = c.e.b.h.e.b.a;
        Arrays.sort(fileArr, g.c);
        for (File name : fileArr) {
            try {
                bVar.b(String.format(Locale.US, "Found Non Fatal for session ID %s in %s ", new Object[]{str, name.getName()}));
                A(cVar, name);
            } catch (Exception e) {
                if (bVar.a(6)) {
                    Log.e("FirebaseCrashlytics", "Error writting non-fatal to session.", e);
                }
            }
        }
    }

    public final void d(c.e.b.h.e.p.b bVar) {
        if (bVar != null) {
            try {
                bVar.n();
            } catch (IOException e) {
                if (c.e.b.h.e.b.a.a(6)) {
                    Log.e("FirebaseCrashlytics", "Error closing session file stream in the presence of an exception", e);
                }
            }
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:176:0x0462  */
    /* JADX WARNING: Removed duplicated region for block: B:175:0x045f  */
    /* JADX WARNING: Removed duplicated region for block: B:211:0x04b4 A:{SYNTHETIC} */
    /* JADX WARNING: Removed duplicated region for block: B:180:0x047d A:{Catch:{ IOException -> 0x04bc }} */
    /* JADX WARNING: Removed duplicated region for block: B:51:0x0139  */
    /* JADX WARNING: Removed duplicated region for block: B:57:0x0171  */
    /* JADX WARNING: Removed duplicated region for block: B:116:0x0326  */
    /* JADX WARNING: Removed duplicated region for block: B:115:0x031a  */
    /* JADX WARNING: Removed duplicated region for block: B:119:0x0348  */
    /* JADX WARNING: Removed duplicated region for block: B:127:0x0373  */
    /* JADX WARNING: Removed duplicated region for block: B:191:0x04f3  */
    /* JADX WARNING: Removed duplicated region for block: B:108:0x02fd A:{LOOP_END, LOOP:4: B:107:0x02fb->B:108:0x02fd} */
    /* JADX WARNING: Missing exception handler attribute for start block: B:158:0x040f */
    /* JADX WARNING: Removed duplicated region for block: B:47:0x011a A:{Catch:{ all -> 0x010d }} */
    /* JADX WARNING: Removed duplicated region for block: B:51:0x0139  */
    /* JADX WARNING: Removed duplicated region for block: B:57:0x0171  */
    /* JADX WARNING: Removed duplicated region for block: B:115:0x031a  */
    /* JADX WARNING: Removed duplicated region for block: B:116:0x0326  */
    /* JADX WARNING: Removed duplicated region for block: B:119:0x0348  */
    /* JADX WARNING: Removed duplicated region for block: B:127:0x0373  */
    /* JADX WARNING: Removed duplicated region for block: B:191:0x04f3  */
    /* JADX WARNING: Removed duplicated region for block: B:108:0x02fd A:{LOOP_END, LOOP:4: B:107:0x02fb->B:108:0x02fd} */
    /* JADX WARNING: Removed duplicated region for block: B:108:0x02fd A:{LOOP_END, LOOP:4: B:107:0x02fb->B:108:0x02fd} */
    public final void f(int r18, boolean r19) throws java.lang.Exception {
        /*
        r17 = this;
        r1 = r17;
        r2 = r18;
        r3 = r19;
        r4 = c.e.b.h.e.b.a;
        r0 = r3 + 8;
        r5 = new java.util.HashSet;
        r5.<init>();
        r6 = r17.s();
        r7 = r6.length;
        r0 = java.lang.Math.min(r0, r7);
        r7 = 0;
        r8 = 0;
    L_0x001a:
        if (r8 >= r0) goto L_0x0028;
    L_0x001c:
        r9 = r6[r8];
        r9 = o(r9);
        r5.add(r9);
        r8 = r8 + 1;
        goto L_0x001a;
    L_0x0028:
        r0 = r1.l;
        r0 = r0.b;
        r0 = (c.e.b.h.e.k.t.k) r0;
        r0 = r0.a();
        r0 = r0.listFiles();
        if (r0 == 0) goto L_0x005e;
    L_0x0038:
        r6 = r0.length;
        r8 = 0;
    L_0x003a:
        if (r8 >= r6) goto L_0x005e;
    L_0x003c:
        r9 = r0[r8];
        r10 = r9.getName();
        r11 = ".temp";
        r11 = r10.lastIndexOf(r11);
        r12 = -1;
        if (r11 != r12) goto L_0x004c;
    L_0x004b:
        goto L_0x0052;
    L_0x004c:
        r12 = 20;
        r10 = r10.substring(r12, r11);
    L_0x0052:
        r10 = r5.contains(r10);
        if (r10 != 0) goto L_0x005b;
    L_0x0058:
        r9.delete();
    L_0x005b:
        r8 = r8 + 1;
        goto L_0x003a;
    L_0x005e:
        r0 = new c.e.b.h.e.k.t$g;
        r6 = 0;
        r0.m1744init(r6);
        r8 = r17.l();
        r0 = r(r8, r0);
        r8 = r0.length;
        r9 = 0;
    L_0x006e:
        r10 = 1;
        if (r9 >= r8) goto L_0x00bf;
    L_0x0071:
        r11 = r0[r9];
        r12 = r11.getName();
        r13 = B;
        r13 = r13.matcher(r12);
        r14 = r13.matches();
        if (r14 != 0) goto L_0x009b;
    L_0x0083:
        r10 = new java.lang.StringBuilder;
        r10.<init>();
        r13 = "Deleting unknown file: ";
        r10.append(r13);
        r10.append(r12);
        r10 = r10.toString();
        r4.b(r10);
        r11.delete();
        goto L_0x00bc;
    L_0x009b:
        r10 = r13.group(r10);
        r10 = r5.contains(r10);
        if (r10 != 0) goto L_0x00bc;
    L_0x00a5:
        r10 = new java.lang.StringBuilder;
        r10.<init>();
        r13 = "Trimming session file: ";
        r10.append(r13);
        r10.append(r12);
        r10 = r10.toString();
        r4.b(r10);
        r11.delete();
    L_0x00bc:
        r9 = r9 + 1;
        goto L_0x006e;
    L_0x00bf:
        r5 = r17.s();
        r0 = r5.length;
        if (r0 > r3) goto L_0x00cc;
    L_0x00c6:
        r0 = "No open sessions to be closed.";
        r4.b(r0);
        return;
    L_0x00cc:
        r0 = r5[r3];
        r8 = o(r0);
        r0 = r17.p();
        if (r0 == 0) goto L_0x00db;
    L_0x00d8:
        r0 = r1.d;
        goto L_0x0127;
    L_0x00db:
        r0 = new c.e.b.h.e.k.t0;
        r9 = r17.l();
        r0.m1750init(r9);
        r9 = "Failed to close user metadata file.";
        r0 = r0.a(r8);
        r11 = r0.exists();
        if (r11 != 0) goto L_0x00f6;
    L_0x00f0:
        r0 = new c.e.b.h.e.k.y0;
        r0.m1757init();
        goto L_0x0127;
    L_0x00f6:
        r11 = new java.io.FileInputStream;	 Catch:{ Exception -> 0x0110 }
        r11.<init>(r0);	 Catch:{ Exception -> 0x0110 }
        r0 = c.e.b.h.e.k.g.u(r11);	 Catch:{ Exception -> 0x010a, all -> 0x0107 }
        r0 = c.e.b.h.e.k.t0.b(r0);	 Catch:{ Exception -> 0x010a, all -> 0x0107 }
        c.e.b.h.e.k.g.c(r11, r9);
        goto L_0x0127;
    L_0x0107:
        r0 = move-exception;
        goto L_0x050d;
    L_0x010a:
        r0 = move-exception;
        r6 = r11;
        goto L_0x0111;
    L_0x010d:
        r0 = move-exception;
        goto L_0x050c;
    L_0x0110:
        r0 = move-exception;
    L_0x0111:
        r11 = "Error deserializing user metadata.";
        r12 = 6;
        r12 = r4.a(r12);	 Catch:{ all -> 0x010d }
        if (r12 == 0) goto L_0x011f;
    L_0x011a:
        r12 = "FirebaseCrashlytics";
        android.util.Log.e(r12, r11, r0);	 Catch:{ all -> 0x010d }
    L_0x011f:
        c.e.b.h.e.k.g.c(r6, r9);
        r0 = new c.e.b.h.e.k.y0;
        r0.m1757init();
    L_0x0127:
        r6 = new c.e.b.h.e.k.v;
        r6.m6095init(r1, r0);
        r0 = "SessionUser";
        r1.z(r8, r0, r6);
        r0 = r1.o;
        r0 = r0.h(r8);
        if (r0 == 0) goto L_0x0168;
    L_0x0139:
        r0 = "Finalizing native report for session ";
        c.b.a.a.a.u(r0, r8, r4);
        r0 = r1.o;
        r0 = r0.b(r8);
        java.util.Objects.requireNonNull(r0);
        r0 = new java.lang.StringBuilder;
        r0.<init>();
        r6 = "No minidump data found for session ";
        r0.append(r6);
        r0.append(r8);
        r0 = r0.toString();
        r4.f(r0);
        r0 = r1.o;
        r0 = r0.a(r8);
        if (r0 != 0) goto L_0x0168;
    L_0x0163:
        r0 = "Could not finalize native session: ";
        c.b.a.a.a.u(r0, r8, r4);
    L_0x0168:
        r0 = "Closing open sessions.";
        r4.b(r0);
        r6 = r3;
    L_0x016e:
        r0 = r5.length;
        if (r6 >= r0) goto L_0x0318;
    L_0x0171:
        r0 = r5[r6];
        r8 = o(r0);
        r9 = new java.lang.StringBuilder;
        r9.<init>();
        r11 = "Closing session: ";
        r9.append(r11);
        r9.append(r8);
        r9 = r9.toString();
        r4.b(r9);
        r9 = new java.lang.StringBuilder;
        r9.<init>();
        r11 = "Collecting session parts for ID ";
        r9.append(r11);
        r9.append(r8);
        r9 = r9.toString();
        r4.b(r9);
        r9 = new c.e.b.h.e.k.t$i;
        r11 = "SessionCrash";
        r11 = c.b.a.a.a.D(r8, r11);
        r9.m1745init(r11);
        r11 = r17.l();
        r9 = r(r11, r9);
        r11 = r9.length;
        if (r11 <= 0) goto L_0x01b7;
    L_0x01b5:
        r11 = 1;
        goto L_0x01b8;
    L_0x01b7:
        r11 = 0;
    L_0x01b8:
        r12 = java.util.Locale.US;
        r13 = 2;
        r14 = new java.lang.Object[r13];
        r14[r7] = r8;
        r15 = java.lang.Boolean.valueOf(r11);
        r14[r10] = r15;
        r10 = "Session %s has fatal exception: %s";
        r10 = java.lang.String.format(r12, r10, r14);
        r4.b(r10);
        r10 = new c.e.b.h.e.k.t$i;
        r14 = "SessionEvent";
        r15 = c.b.a.a.a.D(r8, r14);
        r10.m1745init(r15);
        r15 = r17.l();
        r10 = r(r15, r10);
        r15 = r10.length;
        if (r15 <= 0) goto L_0x01e6;
    L_0x01e4:
        r15 = 1;
        goto L_0x01e7;
    L_0x01e6:
        r15 = 0;
    L_0x01e7:
        r13 = new java.lang.Object[r13];
        r13[r7] = r8;
        r7 = java.lang.Boolean.valueOf(r15);
        r16 = 1;
        r13[r16] = r7;
        r7 = "Session %s has non-fatal exceptions: %s";
        r7 = java.lang.String.format(r12, r7, r13);
        r4.b(r7);
        if (r11 != 0) goto L_0x0208;
    L_0x01fe:
        if (r15 == 0) goto L_0x0201;
    L_0x0200:
        goto L_0x0208;
    L_0x0201:
        r0 = "No events present for session ID ";
        c.b.a.a.a.u(r0, r8, r4);
        goto L_0x02d8;
    L_0x0208:
        r7 = r10.length;
        if (r7 <= r2) goto L_0x0241;
    L_0x020b:
        r7 = 1;
        r7 = new java.lang.Object[r7];
        r10 = java.lang.Integer.valueOf(r18);
        r13 = 0;
        r7[r13] = r10;
        r10 = "Trimming down to %d logged exceptions.";
        r7 = java.lang.String.format(r12, r10, r7);
        r4.b(r7);
        r7 = r17.l();
        r10 = new c.e.b.h.e.k.t$i;
        r12 = c.b.a.a.a.D(r8, r14);
        r10.m1745init(r12);
        r12 = A;
        c.e.b.h.e.k.a1.b(r7, r10, r2, r12);
        r7 = new c.e.b.h.e.k.t$i;
        r10 = c.b.a.a.a.D(r8, r14);
        r7.m1745init(r10);
        r10 = r17.l();
        r10 = r(r10, r7);
    L_0x0241:
        if (r11 == 0) goto L_0x0247;
    L_0x0243:
        r7 = 0;
        r7 = r9[r7];
        goto L_0x0248;
    L_0x0247:
        r7 = 0;
    L_0x0248:
        r9 = "Failed to close CLS file";
        r11 = "Error flushing session file stream";
        if (r7 == 0) goto L_0x0250;
    L_0x024e:
        r12 = 1;
        goto L_0x0251;
    L_0x0250:
        r12 = 0;
    L_0x0251:
        if (r12 == 0) goto L_0x0258;
    L_0x0253:
        r13 = r17.k();
        goto L_0x025c;
    L_0x0258:
        r13 = r17.n();
    L_0x025c:
        r14 = r13.exists();
        if (r14 != 0) goto L_0x0265;
    L_0x0262:
        r13.mkdirs();
    L_0x0265:
        r14 = new c.e.b.h.e.p.b;	 Catch:{ Exception -> 0x02bb, all -> 0x02b7 }
        r14.m1821init(r13, r8);	 Catch:{ Exception -> 0x02bb, all -> 0x02b7 }
        r13 = c.e.b.h.e.p.c.l(r14);	 Catch:{ Exception -> 0x02b4, all -> 0x02b1 }
        r15 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x02af }
        r15.<init>();	 Catch:{ Exception -> 0x02af }
        r2 = "Collecting SessionStart data for session ID ";
        r15.append(r2);	 Catch:{ Exception -> 0x02af }
        r15.append(r8);	 Catch:{ Exception -> 0x02af }
        r2 = r15.toString();	 Catch:{ Exception -> 0x02af }
        r4.b(r2);	 Catch:{ Exception -> 0x02af }
        A(r13, r0);	 Catch:{ Exception -> 0x02af }
        r2 = j();	 Catch:{ Exception -> 0x02af }
        r0 = 4;
        r13.v(r0, r2);	 Catch:{ Exception -> 0x02af }
        r0 = 5;
        r13.n(r0, r12);	 Catch:{ Exception -> 0x02af }
        r0 = 11;
        r2 = 1;
        r13.u(r0, r2);	 Catch:{ Exception -> 0x02af }
        r0 = 12;
        r2 = 3;
        r13.p(r0, r2);	 Catch:{ Exception -> 0x02af }
        r1.w(r13, r8);	 Catch:{ Exception -> 0x02af }
        x(r13, r10, r8);	 Catch:{ Exception -> 0x02af }
        if (r12 == 0) goto L_0x02a8;
    L_0x02a5:
        A(r13, r7);	 Catch:{ Exception -> 0x02af }
    L_0x02a8:
        c.e.b.h.e.k.g.g(r13, r11);
        c.e.b.h.e.k.g.c(r14, r9);
        goto L_0x02d8;
    L_0x02af:
        r0 = move-exception;
        goto L_0x02be;
    L_0x02b1:
        r0 = move-exception;
        r2 = 0;
        goto L_0x0311;
    L_0x02b4:
        r0 = move-exception;
        r13 = 0;
        goto L_0x02be;
    L_0x02b7:
        r0 = move-exception;
        r2 = 0;
        r14 = 0;
        goto L_0x0311;
    L_0x02bb:
        r0 = move-exception;
        r13 = 0;
        r14 = 0;
    L_0x02be:
        r2 = new java.lang.StringBuilder;	 Catch:{ all -> 0x030f }
        r2.<init>();	 Catch:{ all -> 0x030f }
        r3 = "Failed to write session file for session ID: ";
        r2.append(r3);	 Catch:{ all -> 0x030f }
        r2.append(r8);	 Catch:{ all -> 0x030f }
        r2 = r2.toString();	 Catch:{ all -> 0x030f }
        r4.e(r2, r0);	 Catch:{ all -> 0x030f }
        c.e.b.h.e.k.g.g(r13, r11);
        r1.d(r14);
    L_0x02d8:
        r0 = new java.lang.StringBuilder;
        r0.<init>();
        r2 = "Removing session part files for ID ";
        r0.append(r2);
        r0.append(r8);
        r0 = r0.toString();
        r4.b(r0);
        r0 = new c.e.b.h.e.k.t$o;
        r0.m1748init(r8);
        r2 = r17.l();
        r0 = r(r2, r0);
        r2 = r0.length;
        r3 = 0;
    L_0x02fb:
        if (r3 >= r2) goto L_0x0305;
    L_0x02fd:
        r7 = r0[r3];
        r7.delete();
        r3 = r3 + 1;
        goto L_0x02fb;
    L_0x0305:
        r6 = r6 + 1;
        r7 = 0;
        r10 = 1;
        r2 = r18;
        r3 = r19;
        goto L_0x016e;
    L_0x030f:
        r0 = move-exception;
        r2 = r13;
    L_0x0311:
        c.e.b.h.e.k.g.g(r2, r11);
        c.e.b.h.e.k.g.c(r14, r9);
        throw r0;
    L_0x0318:
        if (r19 == 0) goto L_0x0326;
    L_0x031a:
        r0 = 0;
        r0 = r5[r0];
        r0 = o(r0);
        r0 = u(r0);
        goto L_0x0327;
    L_0x0326:
        r0 = 0;
    L_0x0327:
        r2 = r1.s;
        r5 = j();
        r2 = r2.b;
        r3 = new c.e.b.h.e.o.b;
        r3.m1806init(r0);
        r0 = r2.b;
        r0 = c.e.b.h.e.o.g.f(r0, r3);
        r3 = c.e.b.h.e.o.g.j;
        java.util.Collections.sort(r0, r3);
        r3 = r0.size();
        r7 = 8;
        if (r3 > r7) goto L_0x0348;
    L_0x0347:
        goto L_0x0369;
    L_0x0348:
        r3 = r0.size();
        r3 = r0.subList(r7, r3);
        r3 = r3.iterator();
    L_0x0354:
        r8 = r3.hasNext();
        if (r8 == 0) goto L_0x0364;
    L_0x035a:
        r8 = r3.next();
        r8 = (java.io.File) r8;
        c.e.b.h.e.o.g.k(r8);
        goto L_0x0354;
    L_0x0364:
        r3 = 0;
        r0 = r0.subList(r3, r7);
    L_0x0369:
        r3 = r0.iterator();
    L_0x036d:
        r0 = r3.hasNext();
        if (r0 == 0) goto L_0x04d6;
    L_0x0373:
        r0 = r3.next();
        r7 = r0;
        r7 = (java.io.File) r7;
        r0 = "Finalizing report for session ";
        r0 = c.b.a.a.a.g(r0);
        r8 = r7.getName();
        r0.append(r8);
        r0 = r0.toString();
        r4.b(r0);
        r0 = c.e.b.h.e.o.g.k;
        r0 = c.e.b.h.e.o.g.g(r7, r0);
        r8 = r0.isEmpty();
        if (r8 == 0) goto L_0x03b5;
    L_0x039a:
        r0 = "Session ";
        r0 = c.b.a.a.a.g(r0);
        r8 = r7.getName();
        r0.append(r8);
        r8 = " has no events.";
        r0.append(r8);
        r0 = r0.toString();
        r4.b(r0);
        goto L_0x04d1;
    L_0x03b5:
        java.util.Collections.sort(r0);
        r8 = new java.util.ArrayList;
        r8.<init>();
        r9 = r0.iterator();
    L_0x03c1:
        r0 = 0;
        r10 = 0;
    L_0x03c3:
        r0 = r9.hasNext();
        if (r0 == 0) goto L_0x042d;
    L_0x03c9:
        r0 = r9.next();
        r11 = r0;
        r11 = (java.io.File) r11;
        r0 = c.e.b.h.e.o.g.i;	 Catch:{ IOException -> 0x0417 }
        r12 = c.e.b.h.e.o.g.j(r11);	 Catch:{ IOException -> 0x0417 }
        java.util.Objects.requireNonNull(r0);	 Catch:{ IOException -> 0x0417 }
        r13 = new android.util.JsonReader;	 Catch:{ IllegalStateException -> 0x0410 }
        r0 = new java.io.StringReader;	 Catch:{ IllegalStateException -> 0x0410 }
        r0.<init>(r12);	 Catch:{ IllegalStateException -> 0x0410 }
        r13.<init>(r0);	 Catch:{ IllegalStateException -> 0x0410 }
        r0 = c.e.b.h.e.m.x.h.b(r13);	 Catch:{ all -> 0x040a }
        r13.close();	 Catch:{ IllegalStateException -> 0x0410 }
        r8.add(r0);	 Catch:{ IOException -> 0x0417 }
        if (r10 != 0) goto L_0x0408;
    L_0x03ef:
        r0 = r11.getName();	 Catch:{ IOException -> 0x0417 }
        r12 = "event";
        r12 = r0.startsWith(r12);	 Catch:{ IOException -> 0x0417 }
        if (r12 == 0) goto L_0x0405;
    L_0x03fb:
        r12 = "_";
        r0 = r0.endsWith(r12);	 Catch:{ IOException -> 0x0417 }
        if (r0 == 0) goto L_0x0405;
    L_0x0403:
        r0 = 1;
        goto L_0x0406;
    L_0x0405:
        r0 = 0;
    L_0x0406:
        if (r0 == 0) goto L_0x03c1;
    L_0x0408:
        r10 = 1;
        goto L_0x03c3;
    L_0x040a:
        r0 = move-exception;
        r12 = r0;
        r13.close();	 Catch:{ all -> 0x040f }
    L_0x040f:
        throw r12;	 Catch:{ IllegalStateException -> 0x0410 }
    L_0x0410:
        r0 = move-exception;
        r12 = new java.io.IOException;	 Catch:{ IOException -> 0x0417 }
        r12.<init>(r0);	 Catch:{ IOException -> 0x0417 }
        throw r12;	 Catch:{ IOException -> 0x0417 }
    L_0x0417:
        r0 = move-exception;
        r12 = new java.lang.StringBuilder;
        r12.<init>();
        r13 = "Could not add event to report for ";
        r12.append(r13);
        r12.append(r11);
        r11 = r12.toString();
        r4.c(r11, r0);
        goto L_0x03c3;
    L_0x042d:
        r0 = new java.io.File;
        r9 = "user";
        r0.<init>(r7, r9);
        r9 = r0.isFile();
        if (r9 == 0) goto L_0x0455;
    L_0x043a:
        r0 = c.e.b.h.e.o.g.j(r0);	 Catch:{ IOException -> 0x043f }
        goto L_0x0456;
    L_0x043f:
        r0 = move-exception;
        r9 = r0;
        r0 = "Could not read user ID file in ";
        r0 = c.b.a.a.a.g(r0);
        r11 = r7.getName();
        r0.append(r11);
        r0 = r0.toString();
        r4.c(r0, r9);
    L_0x0455:
        r0 = 0;
    L_0x0456:
        r9 = new java.io.File;
        r11 = "report";
        r9.<init>(r7, r11);
        if (r10 == 0) goto L_0x0462;
    L_0x045f:
        r11 = r2.c;
        goto L_0x0464;
    L_0x0462:
        r11 = r2.d;
    L_0x0464:
        r12 = c.e.b.h.e.o.g.i;	 Catch:{ IOException -> 0x04bc }
        r13 = c.e.b.h.e.o.g.j(r9);	 Catch:{ IOException -> 0x04bc }
        r13 = r12.f(r13);	 Catch:{ IOException -> 0x04bc }
        r0 = r13.j(r5, r10, r0);	 Catch:{ IOException -> 0x04bc }
        r10 = new c.e.b.h.e.m.w;	 Catch:{ IOException -> 0x04bc }
        r10.m1796init(r8);	 Catch:{ IOException -> 0x04bc }
        r8 = r0.h();	 Catch:{ IOException -> 0x04bc }
        if (r8 == 0) goto L_0x04b4;
    L_0x047d:
        r8 = r0.i();	 Catch:{ IOException -> 0x04bc }
        r0 = r0.h();	 Catch:{ IOException -> 0x04bc }
        r0 = r0.l();	 Catch:{ IOException -> 0x04bc }
        r0 = (c.e.b.h.e.m.f.b) r0;	 Catch:{ IOException -> 0x04bc }
        r0.j = r10;	 Catch:{ IOException -> 0x04bc }
        r0 = r0.a();	 Catch:{ IOException -> 0x04bc }
        r8 = (c.e.b.h.e.m.b.b) r8;	 Catch:{ IOException -> 0x04bc }
        r8.g = r0;	 Catch:{ IOException -> 0x04bc }
        r0 = r8.a();	 Catch:{ IOException -> 0x04bc }
        r8 = r0.h();	 Catch:{ IOException -> 0x04bc }
        if (r8 != 0) goto L_0x04a0;
    L_0x049f:
        goto L_0x04d1;
    L_0x04a0:
        r10 = new java.io.File;	 Catch:{ IOException -> 0x04bc }
        c.e.b.h.e.o.g.i(r11);	 Catch:{ IOException -> 0x04bc }
        r8 = r8.g();	 Catch:{ IOException -> 0x04bc }
        r10.<init>(r11, r8);	 Catch:{ IOException -> 0x04bc }
        r0 = r12.g(r0);	 Catch:{ IOException -> 0x04bc }
        c.e.b.h.e.o.g.l(r10, r0);	 Catch:{ IOException -> 0x04bc }
        goto L_0x04d1;
    L_0x04b4:
        r0 = new java.lang.IllegalStateException;	 Catch:{ IOException -> 0x04bc }
        r8 = "Reports without sessions cannot have events added to them.";
        r0.<init>(r8);	 Catch:{ IOException -> 0x04bc }
        throw r0;	 Catch:{ IOException -> 0x04bc }
    L_0x04bc:
        r0 = move-exception;
        r8 = new java.lang.StringBuilder;
        r8.<init>();
        r10 = "Could not synthesize final report file for ";
        r8.append(r10);
        r8.append(r9);
        r8 = r8.toString();
        r4.c(r8, r0);
    L_0x04d1:
        c.e.b.h.e.o.g.k(r7);
        goto L_0x036d;
    L_0x04d6:
        r0 = r2.f;
        r0 = (c.e.b.h.e.s.d) r0;
        r0 = r0.c();
        r0 = r0.a();
        java.util.Objects.requireNonNull(r0);
        r0 = r2.e();
        r0 = (java.util.ArrayList) r0;
        r2 = r0.size();
        r3 = 4;
        if (r2 > r3) goto L_0x04f3;
    L_0x04f2:
        goto L_0x050b;
    L_0x04f3:
        r0 = r0.subList(r3, r2);
        r0 = r0.iterator();
    L_0x04fb:
        r2 = r0.hasNext();
        if (r2 == 0) goto L_0x050b;
    L_0x0501:
        r2 = r0.next();
        r2 = (java.io.File) r2;
        r2.delete();
        goto L_0x04fb;
    L_0x050b:
        return;
    L_0x050c:
        r11 = r6;
    L_0x050d:
        c.e.b.h.e.k.g.c(r11, r9);
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.b.h.e.k.t.f(int, boolean):void");
    }

    public final void g(long j) {
        try {
            File l = l();
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(".ae");
            stringBuilder.append(j);
            new File(l, stringBuilder.toString()).createNewFile();
        } catch (IOException unused) {
            c.e.b.h.e.b.a.b("Could not write app exception marker.");
        }
    }

    public boolean h(int i) {
        c.e.b.h.e.b bVar = c.e.b.h.e.b.a;
        this.e.a();
        if (p()) {
            bVar.b("Skipping session finalization because a crash has already occurred.");
            return false;
        }
        bVar.b("Finalizing previously open sessions.");
        try {
            f(i, true);
            bVar.b("Closed all previously open sessions");
            return true;
        } catch (Exception e) {
            if (bVar.a(6)) {
                Log.e("FirebaseCrashlytics", "Unable to finalize previously open sessions.", e);
            }
            return false;
        }
    }

    public final String i() {
        File[] s = s();
        return s.length > 0 ? o(s[0]) : null;
    }

    public File k() {
        return new File(l(), "fatal-sessions");
    }

    public File l() {
        return this.h.a();
    }

    public File m() {
        return new File(l(), "native-sessions");
    }

    public File n() {
        return new File(l(), "nonfatal-sessions");
    }

    public boolean p() {
        k0 k0Var = this.t;
        return k0Var != null && k0Var.d.get();
    }

    public File[] q() {
        LinkedList linkedList = new LinkedList();
        File k = k();
        FilenameFilter filenameFilter = y;
        Object[] listFiles = k.listFiles(filenameFilter);
        if (listFiles == null) {
            listFiles = new File[0];
        }
        Collections.addAll(linkedList, listFiles);
        listFiles = n().listFiles(filenameFilter);
        if (listFiles == null) {
            listFiles = new File[0];
        }
        Collections.addAll(linkedList, listFiles);
        Collections.addAll(linkedList, r(l(), filenameFilter));
        return (File[]) linkedList.toArray(new File[linkedList.size()]);
    }

    public final File[] s() {
        File[] r = r(l(), x);
        Arrays.sort(r, z);
        return r;
    }

    public final c.e.a.b.g.g<Void> t(long j) {
        Object obj;
        try {
            Class.forName("com.google.firebase.crash.FirebaseCrash");
            obj = 1;
        } catch (ClassNotFoundException unused) {
            obj = null;
        }
        if (obj != null) {
            c.e.b.h.e.b.a.b("Skipping logging Crashlytics event to Firebase, FirebaseCrash exists");
            return c.e.a.b.b.j.d.b(null);
        }
        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
        b bVar = new b(j);
        b.i.b.f.S(scheduledThreadPoolExecutor, "Executor must not be null");
        b.i.b.f.S(bVar, "Callback must not be null");
        a0 a0Var = new a0();
        scheduledThreadPoolExecutor.execute(new b0(a0Var, bVar));
        return a0Var;
    }

    public c.e.a.b.g.g<Void> v(float f, c.e.a.b.g.g<c.e.b.h.e.s.i.b> gVar) {
        Boolean bool = Boolean.FALSE;
        c.e.b.h.e.b bVar = c.e.b.h.e.b.a;
        c.e.b.h.e.q.a aVar = this.m;
        File[] q = t.this.q();
        File[] listFiles = t.this.m().listFiles();
        int i = 0;
        if (listFiles == null) {
            listFiles = new File[0];
        }
        if ((q != null && q.length > 0) || listFiles.length > 0) {
            i = 1;
        }
        if (i == 0) {
            bVar.b("No reports are available.");
            this.u.b(bool);
            return c.e.a.b.b.j.d.b(null);
        }
        a0 b;
        bVar.b("Unsent reports are available.");
        Boolean bool2 = Boolean.TRUE;
        if (this.b.a()) {
            bVar.b("Automatic data collection is enabled. Allowing upload.");
            this.u.b(bool);
            b = c.e.a.b.b.j.d.b(bool2);
        } else {
            bVar.b("Automatic data collection is disabled.");
            bVar.b("Notifying that unsent reports are available.");
            this.u.b(bool2);
            l0 l0Var = this.b;
            synchronized (l0Var.c) {
                b = l0Var.d.a;
            }
            z zVar = new z(this);
            Objects.requireNonNull(b);
            c.e.a.b.g.g l = b.l(c.e.a.b.g.i.a, zVar);
            bVar.b("Waiting for send/deleteUnsentReports to be called.");
            a0 a0Var = this.v.a;
            FilenameFilter filenameFilter = a1.a;
            c.e.a.b.g.h hVar = new c.e.a.b.g.h();
            b1 b1Var = new b1(hVar);
            l.d(b1Var);
            a0Var.d(b1Var);
            b = hVar.a;
        }
        f fVar = new f(gVar, f);
        b = b;
        Objects.requireNonNull(b);
        return b.l(c.e.a.b.g.i.a, fVar);
    }

    public final void w(c.e.b.h.e.p.c cVar, String str) throws IOException {
        c.e.b.h.e.b bVar = c.e.b.h.e.b.a;
        for (String str2 : D) {
            File[] r = r(l(), new i(c.b.a.a.a.E(str, str2, ".cls")));
            String str3 = " data for session ID ";
            if (r.length == 0) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("Can't find ");
                stringBuilder.append(str2);
                stringBuilder.append(str3);
                stringBuilder.append(str);
                bVar.b(stringBuilder.toString());
            } else {
                StringBuilder stringBuilder2 = new StringBuilder();
                stringBuilder2.append("Collecting ");
                stringBuilder2.append(str2);
                stringBuilder2.append(str3);
                stringBuilder2.append(str);
                bVar.b(stringBuilder2.toString());
                A(cVar, r[0]);
            }
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:20:0x00f4  */
    /* JADX WARNING: Removed duplicated region for block: B:19:0x00f2  */
    /* JADX WARNING: Removed duplicated region for block: B:23:0x0113  */
    /* JADX WARNING: Removed duplicated region for block: B:22:0x0101  */
    /* JADX WARNING: Removed duplicated region for block: B:26:0x019b  */
    /* JADX WARNING: Removed duplicated region for block: B:29:0x01f3 A:{LOOP_END, LOOP:1: B:28:0x01f1->B:29:0x01f3} */
    /* JADX WARNING: Removed duplicated region for block: B:32:0x023d  */
    /* JADX WARNING: Removed duplicated region for block: B:39:0x0256  */
    /* JADX WARNING: Removed duplicated region for block: B:45:0x0297  */
    /* JADX WARNING: Removed duplicated region for block: B:52:0x02c1  */
    /* JADX WARNING: Removed duplicated region for block: B:55:0x030a  */
    public final void y(c.e.b.h.e.p.c r34, java.lang.Thread r35, java.lang.Throwable r36, long r37, java.lang.String r39, boolean r40) throws java.lang.Exception {
        /*
        r33 = this;
        r0 = r33;
        r1 = r34;
        r2 = r37;
        r15 = new c.e.b.h.e.t.e;
        r4 = r0.p;
        r5 = r36;
        r15.m1844init(r5, r4);
        r4 = r0.a;
        r5 = c.e.b.h.e.k.e.a(r4);
        r14 = r5.a;
        r16 = r5.b();
        r13 = c.e.b.h.e.k.g.l(r4);
        r5 = r4.getResources();
        r5 = r5.getConfiguration();
        r12 = r5.orientation;
        r5 = c.e.b.h.e.k.g.o();
        r7 = new android.app.ActivityManager$MemoryInfo;
        r7.<init>();
        r8 = "activity";
        r8 = r4.getSystemService(r8);
        r8 = (android.app.ActivityManager) r8;
        r8.getMemoryInfo(r7);
        r7 = r7.availMem;
        r10 = r5 - r7;
        r5 = android.os.Environment.getDataDirectory();
        r5 = r5.getPath();
        r8 = c.e.b.h.e.k.g.a(r5);
        r5 = r4.getPackageName();
        r7 = c.e.b.h.e.k.g.h(r5, r4);
        r6 = new java.util.LinkedList;
        r6.<init>();
        r5 = r15.c;
        r36 = r5;
        r5 = r0.i;
        r5 = r5.b;
        r17 = r7;
        r7 = r0.g;
        r7 = r7.c;
        r18 = r8;
        if (r40 == 0) goto L_0x00b1;
    L_0x006c:
        r20 = java.lang.Thread.getAllStackTraces();
        r9 = r20.size();
        r9 = new java.lang.Thread[r9];
        r20 = r20.entrySet();
        r20 = r20.iterator();
        r22 = 0;
    L_0x0080:
        r23 = r20.hasNext();
        if (r23 == 0) goto L_0x00ad;
    L_0x0086:
        r23 = r20.next();
        r23 = (java.util.Map.Entry) r23;
        r24 = r23.getKey();
        r24 = (java.lang.Thread) r24;
        r9[r22] = r24;
        r8 = r0.p;
        r23 = r23.getValue();
        r40 = r9;
        r9 = r23;
        r9 = (java.lang.StackTraceElement[]) r9;
        r8 = r8.a(r9);
        r6.add(r8);
        r8 = 1;
        r22 = r22 + 1;
        r9 = r40;
        goto L_0x0080;
    L_0x00ad:
        r40 = r9;
        r8 = 1;
        goto L_0x00b5;
    L_0x00b1:
        r9 = 0;
        r8 = new java.lang.Thread[r9];
        r9 = r8;
    L_0x00b5:
        r8 = "com.crashlytics.CollectCustomKeys";
        r20 = r6;
        r6 = 1;
        r4 = c.e.b.h.e.k.g.i(r4, r8, r6);
        if (r4 != 0) goto L_0x00c6;
    L_0x00c0:
        r4 = new java.util.TreeMap;
        r4.<init>();
        goto L_0x00de;
    L_0x00c6:
        r4 = r0.d;
        r4 = r4.b;
        r4 = java.util.Collections.unmodifiableMap(r4);
        if (r4 == 0) goto L_0x00de;
    L_0x00d0:
        r8 = r4.size();
        if (r8 <= r6) goto L_0x00de;
    L_0x00d6:
        r6 = new java.util.TreeMap;
        r6.<init>(r4);
        r22 = r6;
        goto L_0x00e0;
    L_0x00de:
        r22 = r4;
    L_0x00e0:
        r4 = r0.l;
        r4 = r4.c;
        r4 = r4.c();
        r6 = c.e.b.h.e.p.d.a;
        r8 = c.e.b.h.e.p.a.a(r7);
        r7 = "";
        if (r5 != 0) goto L_0x00f4;
    L_0x00f2:
        r6 = 0;
        goto L_0x00ff;
    L_0x00f4:
        r6 = "-";
        r5 = r5.replace(r6, r7);
        r5 = c.e.b.h.e.p.a.a(r5);
        r6 = r5;
    L_0x00ff:
        if (r4 == 0) goto L_0x0113;
    L_0x0101:
        r5 = r4.length;
        r23 = r6;
        r6 = new byte[r5];
        r25 = r7;
        r7 = 0;
        java.lang.System.arraycopy(r4, r7, r6, r7, r5);
        r4 = new c.e.b.h.e.p.a;
        r4.m1818init(r6);
        r7 = r4;
        goto L_0x011f;
    L_0x0113:
        r23 = r6;
        r25 = r7;
        r4 = c.e.b.h.e.b.a;
        r5 = "No log data to include with this event.";
        r4.b(r5);
        r7 = 0;
    L_0x011f:
        r4 = 10;
        r6 = 2;
        r1.t(r4, r6);
        r5 = 1;
        r4 = c.e.b.h.e.p.c.k(r5, r2);
        r21 = 0;
        r4 = r4 + 0;
        r5 = c.e.b.h.e.p.a.a(r39);
        r5 = c.e.b.h.e.p.c.b(r6, r5);
        r26 = r5 + r4;
        r27 = 8;
        r4 = r15;
        r40 = r36;
        r24 = 1;
        r5 = r35;
        r36 = r20;
        r0 = 2;
        r6 = r40;
        r0 = r7;
        r20 = r17;
        r17 = r25;
        r7 = r9;
        r28 = r18;
        r18 = r8;
        r19 = r15;
        r15 = 1;
        r8 = r36;
        r21 = r9;
        r9 = r27;
        r30 = r10;
        r10 = r18;
        r11 = r23;
        r24 = r12;
        r12 = r22;
        r27 = r13;
        r13 = r20;
        r32 = r14;
        r14 = r24;
        r4 = c.e.b.h.e.p.d.f(r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14);
        r14 = 3;
        r5 = c.e.b.h.e.p.c.f(r14);
        r6 = c.e.b.h.e.p.c.d(r4);
        r6 = r6 + r5;
        r6 = r6 + r4;
        r4 = r6 + r26;
        r6 = r32;
        r7 = r16;
        r8 = r27;
        r9 = r24;
        r10 = r30;
        r12 = r28;
        r5 = c.e.b.h.e.p.d.g(r6, r7, r8, r9, r10, r12);
        r13 = 5;
        r6 = c.e.b.h.e.p.c.f(r13);
        r7 = c.e.b.h.e.p.c.d(r5);
        r7 = r7 + r6;
        r7 = r7 + r5;
        r7 = r7 + r4;
        r12 = 6;
        if (r0 == 0) goto L_0x01aa;
    L_0x019b:
        r4 = c.e.b.h.e.p.c.b(r15, r0);
        r5 = c.e.b.h.e.p.c.f(r12);
        r6 = c.e.b.h.e.p.c.d(r4);
        r6 = r6 + r5;
        r6 = r6 + r4;
        r7 = r7 + r6;
    L_0x01aa:
        r1.r(r7);
        r1.v(r15, r2);
        r2 = c.e.b.h.e.p.a.a(r39);
        r3 = 2;
        r1.o(r3, r2);
        r1.t(r14, r3);
        r26 = 8;
        r7 = 8;
        r2 = r19;
        r3 = r35;
        r4 = r40;
        r5 = r21;
        r6 = r36;
        r8 = r18;
        r9 = r23;
        r10 = r22;
        r11 = r20;
        r12 = r24;
        r2 = c.e.b.h.e.p.d.f(r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12);
        r1.r(r2);
        r2 = 2;
        r1.t(r15, r2);
        r2 = r19;
        r7 = r26;
        r2 = c.e.b.h.e.p.d.e(r2, r3, r4, r5, r6, r7, r8, r9);
        r1.r(r2);
        r2 = 4;
        c.e.b.h.e.p.d.m(r1, r3, r4, r2, r15);
        r8 = r21;
        r3 = r8.length;
        r9 = 0;
    L_0x01f1:
        if (r9 >= r3) goto L_0x0204;
    L_0x01f3:
        r4 = r8[r9];
        r5 = r36;
        r6 = r5.get(r9);
        r6 = (java.lang.StackTraceElement[]) r6;
        r7 = 0;
        c.e.b.h.e.p.d.m(r1, r4, r6, r7, r7);
        r9 = r9 + 1;
        goto L_0x01f1;
    L_0x0204:
        r7 = 0;
        r3 = 8;
        r4 = r19;
        r5 = 2;
        c.e.b.h.e.p.d.l(r1, r4, r15, r3, r5);
        r1.t(r14, r5);
        r3 = c.e.b.h.e.p.d.d();
        r1.r(r3);
        r3 = c.e.b.h.e.p.d.a;
        r1.o(r15, r3);
        r1.o(r5, r3);
        r3 = 0;
        r1.v(r14, r3);
        r1.t(r2, r5);
        r6 = r18;
        r8 = r23;
        r9 = c.e.b.h.e.p.d.a(r6, r8);
        r1.r(r9);
        r1.v(r15, r3);
        r1.v(r5, r3);
        r1.o(r14, r6);
        if (r8 == 0) goto L_0x0240;
    L_0x023d:
        r1.o(r2, r8);
    L_0x0240:
        if (r22 == 0) goto L_0x0293;
    L_0x0242:
        r3 = r22.isEmpty();
        if (r3 != 0) goto L_0x0293;
    L_0x0248:
        r3 = r22.entrySet();
        r3 = r3.iterator();
    L_0x0250:
        r4 = r3.hasNext();
        if (r4 == 0) goto L_0x0293;
    L_0x0256:
        r4 = r3.next();
        r4 = (java.util.Map.Entry) r4;
        r5 = 2;
        r1.t(r5, r5);
        r5 = r4.getKey();
        r5 = (java.lang.String) r5;
        r6 = r4.getValue();
        r6 = (java.lang.String) r6;
        r5 = c.e.b.h.e.p.d.b(r5, r6);
        r1.r(r5);
        r5 = r4.getKey();
        r5 = (java.lang.String) r5;
        r5 = c.e.b.h.e.p.a.a(r5);
        r1.o(r15, r5);
        r4 = r4.getValue();
        r4 = (java.lang.String) r4;
        if (r4 != 0) goto L_0x028a;
    L_0x0288:
        r4 = r17;
    L_0x028a:
        r4 = c.e.b.h.e.p.a.a(r4);
        r5 = 2;
        r1.o(r5, r4);
        goto L_0x0250;
    L_0x0293:
        r3 = r20;
        if (r3 == 0) goto L_0x02a3;
    L_0x0297:
        r3 = r3.importance;
        r4 = 100;
        if (r3 == r4) goto L_0x029f;
    L_0x029d:
        r9 = 1;
        goto L_0x02a0;
    L_0x029f:
        r9 = 0;
    L_0x02a0:
        r1.n(r14, r9);
    L_0x02a3:
        r3 = r24;
        r1.u(r2, r3);
        r4 = 2;
        r1.t(r13, r4);
        r6 = r32;
        r7 = r16;
        r8 = r27;
        r9 = r3;
        r10 = r30;
        r4 = 5;
        r12 = r28;
        r5 = c.e.b.h.e.p.d.g(r6, r7, r8, r9, r10, r12);
        r1.r(r5);
        if (r32 == 0) goto L_0x02e8;
    L_0x02c1:
        r5 = r32.floatValue();
        r6 = 13;
        r1.r(r6);
        r5 = java.lang.Float.floatToRawIntBits(r5);
        r6 = r5 & 255;
        r1.q(r6);
        r6 = r5 >> 8;
        r6 = r6 & 255;
        r1.q(r6);
        r6 = r5 >> 16;
        r6 = r6 & 255;
        r1.q(r6);
        r5 = r5 >> 24;
        r5 = r5 & 255;
        r1.q(r5);
    L_0x02e8:
        r5 = 16;
        r1.r(r5);
        r5 = r16 << 1;
        r6 = r16 >> 31;
        r5 = r5 ^ r6;
        r1.r(r5);
        r5 = r27;
        r1.n(r14, r5);
        r1.u(r2, r3);
        r5 = r30;
        r1.v(r4, r5);
        r2 = r28;
        r4 = 6;
        r1.v(r4, r2);
        if (r0 == 0) goto L_0x0318;
    L_0x030a:
        r2 = 2;
        r1.t(r4, r2);
        r2 = c.e.b.h.e.p.c.b(r15, r0);
        r1.r(r2);
        r1.o(r15, r0);
    L_0x0318:
        r0 = r33;
        r1 = r0.l;
        r1 = r1.c;
        r1.d();
        return;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.b.h.e.k.t.y(c.e.b.h.e.p.c, java.lang.Thread, java.lang.Throwable, long, java.lang.String, boolean):void");
    }

    public final void z(String str, String str2, h hVar) throws Exception {
        Throwable th;
        StringBuilder stringBuilder;
        String str3 = "Failed to close session ";
        String str4 = "Failed to flush to session ";
        String str5 = " file.";
        Flushable flushable = null;
        Closeable bVar;
        try {
            c.e.b.h.e.p.c l;
            File l2 = l();
            StringBuilder stringBuilder2 = new StringBuilder();
            stringBuilder2.append(str);
            stringBuilder2.append(str2);
            bVar = new c.e.b.h.e.p.b(l2, stringBuilder2.toString());
            try {
                l = c.e.b.h.e.p.c.l(bVar);
            } catch (Throwable th2) {
                th = th2;
                stringBuilder = new StringBuilder();
                stringBuilder.append(str4);
                stringBuilder.append(str2);
                stringBuilder.append(str5);
                g.g(flushable, stringBuilder.toString());
                stringBuilder = new StringBuilder();
                stringBuilder.append(str3);
                stringBuilder.append(str2);
                stringBuilder.append(str5);
                g.c(bVar, stringBuilder.toString());
                throw th;
            }
            try {
                hVar.a(l);
                StringBuilder stringBuilder3 = new StringBuilder();
                stringBuilder3.append(str4);
                stringBuilder3.append(str2);
                stringBuilder3.append(str5);
                g.g(l, stringBuilder3.toString());
                stringBuilder = new StringBuilder();
                stringBuilder.append(str3);
                stringBuilder.append(str2);
                stringBuilder.append(str5);
                g.c(bVar, stringBuilder.toString());
            } catch (Throwable th3) {
                th = th3;
                flushable = l;
                stringBuilder = new StringBuilder();
                stringBuilder.append(str4);
                stringBuilder.append(str2);
                stringBuilder.append(str5);
                g.g(flushable, stringBuilder.toString());
                stringBuilder = new StringBuilder();
                stringBuilder.append(str3);
                stringBuilder.append(str2);
                stringBuilder.append(str5);
                g.c(bVar, stringBuilder.toString());
                throw th;
            }
        } catch (Throwable th4) {
            th = th4;
            bVar = null;
            stringBuilder = new StringBuilder();
            stringBuilder.append(str4);
            stringBuilder.append(str2);
            stringBuilder.append(str5);
            g.g(flushable, stringBuilder.toString());
            stringBuilder = new StringBuilder();
            stringBuilder.append(str3);
            stringBuilder.append(str2);
            stringBuilder.append(str5);
            g.c(bVar, stringBuilder.toString());
            throw th;
        }
    }
}
